String module
String mavenCommand
String HOME = "/home/apps/wishlist"
String ENV = "prod"

pipeline {
  agent any

  stages {

    stage("准备(prepare)") {
      steps {
        script {
          GString runModule = "${env.选择构建模块}"
          if (runModule.contains('standalone')) {
            module = 'standalone'
          } else {
            module = 'all'
          }
        }
      }
    }

    stage("拉取代码(update)") {
      steps {
        sh """bash ${HOME}/bin/backend.sh update"""
      }
    }
    stage("构建代码(build)") {
      steps {
        script {
          mavenCommand = """bash ${HOME}/bin/backend.sh build"""
//          if (module != '' && module != 'all') {
//            mavenCommand = mavenCommand + " " + module
//          }
        }
        sh mavenCommand
      }
    }
    stage("启动服务(run)") {
      parallel {
        stage("单机(standalone)") {
          when {
            expression {
              return module == 'all' || module == 'standalone'
            }
          }

          steps {
            sh """JENKINS_NODE_COOKIE=dontKillMe bash ${HOME}/bin/backend.sh start standalone -e ${ENV} -w"""
          }
        }
      }
    }
  }
}